package com.tanhua.model.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Questions implements java.io.Serializable{

    private Long qId;//
    private String questionName; //问题
    private String answer; //答案

    @TableField(exist = false)
    private String id;

    @TableField(exist = false)
    private String question;

    @TableField(exist = false)
    private List<Options> options = Collections.emptyList();

    public static List<Questions> questions(List<Questions> questionsList){

        List<Questions> qList = new ArrayList<>();

        for (Questions questions : questionsList) {

            Questions q = new Questions();
            q.setId(questions.getQId().toString());
            q.setQuestion(questions.getQuestionName());
            String answer = questions.getAnswer();
            String[] split = answer.split(",");
            List<Options> list = new ArrayList<>();
            for (int i = 0; i < split.length; i++) {
                Options options = new Options();
                options.setId(String.valueOf(i));
                options.setOption(split[i]);
                list.add(options);
            }

            q.setOptions(list);
            qList.add(q);
        }
        return qList;
    }

}
